package com.rds.web.controller.pms;
import com.rds.document.service.IFolderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rds.common.core.controller.BaseController;
import com.rds.common.core.domain.AjaxResult;
import com.rds.common.core.domain.entity.Document;
import com.rds.common.core.domain.entity.Folder;
import com.rds.common.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 文档库
 *
 * @author rds
 */
@RestController
@RequestMapping("/pms/repository")
public class RepositoryController extends BaseController
{
    @Autowired
    private IFolderService folderService;

    @PreAuthorize("@ss.hasPermi('pms:repository:list')")
    @GetMapping("/list")
    public TableDataInfo list(Folder folder)
    {
        startPage();
        List<Folder> list = folderService.selectFolderList(folder);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('pms:repository:list')")
    @GetMapping("/doclist")
    public TableDataInfo doclist(Document document)
    {
        startPage();
        Set<Long> folderIdList = new HashSet<>();
        if (document.getFolderId() != null && document.getFolderId()>0) {
            folderIdList = folderService.getAllFolderId(document.getFolderId());
        }
//        List<Document> list = documentService.selectDocumentListByFid(document, folderIdList);
        return getDataTable(new ArrayList<>());
    }


    /**
     * 加载列表树
     */
    @GetMapping("/treeData")
    public AjaxResult treeData(Folder folder)
    {
        List<Folder> folders = folderService.selectFolderList(folder);
        return AjaxResult.success(folderService.buildFolderTreeSelect(folders));
    }

}
